#pragma once
#include <WINSOCK2.H>
#include <stdio.h>

#define SERVER_ADDRESS "127.0.0.1"
#define PORT           5150
#define MSGSIZE        1024
#pragma comment(lib, "ws2_32.lib")

enum ClientStatu
{
    UnInit = 0,
    ConnectErr,
    Unlisten,
    listenning,
    ServerErr,
    End,
    Unknow
};

class SocketClientMgr:base::Thread
{
public:

    class Listener
    {
    public:
        virtual void SCM_OnStartCreateConnectBegin()=0;
        virtual void SCM_OnStartCreateConnectEnd(const bool is_succ, const std::string err, const int type) = 0;

        virtual void SCM_OnDisconnect() = 0;

        virtual void SCM_OnReConnectBegin() = 0;
        virtual void SCM_OnReConnectEnd(const bool is_succ, const int type) = 0;

        virtual void SCM_OnSendMessageBegin() = 0;
        virtual void SCM_OnSendMessageEnd(const bool is_succ, const int type) = 0;

        virtual void SCM_OnReceiveBegin() = 0;
        virtual void SCM_OnReceiveEnd(const bool is_succ, const int type, const char* msg) = 0;
        virtual void SCM_OnStatuChange(int statu) = 0;
    };
    SocketClientMgr(Listener* p);
    ~SocketClientMgr();

    void StartCreateConnect();
    void ReConnect();
    void Disconnect();
    void ClientSendMessage(char* szMessage);
    void StartGetMessage();
    void SetStatu(ClientStatu statu);
private:
    Listener* listener_ = nullptr;
    SOCKET      client_;
    ClientStatu statu_ = Unknow;
};

